<?php
class AddContentForm extends Form{
	var $spam_content=array();
	function AddContentForm(){
		Form::Form('AddContentForm');
		
		CGlobal::$website_title="Thêm nội dung Spam";
		$this->link_css('style/manage_item.css');
		
		$this->spam_content	= array(
								'des'			=>'',
								'subject'		=>'',
								'content' 		=>'',
								'status'  		=>0,
								);
	}

	function on_submit(){
		$this->spam_content	= array(
									'des'			=>addslashes(Url::get('des')),
									//'subject'		=>addslashes(AZLib::stripUnicode(Url::get('subject'))),
									'subject'		=>addslashes(Url::get('subject')),
									'content'		=>addslashes(Url::get('content')),
									'time'  		=>TIME_NOW,
									'time_modify'  	=>TIME_NOW,
									'status'  		=>(int)Url::get('status',0),//0:tat,1:bat
									);
		
		$this->checkFormInput('Mô tả','des',	$this->spam_content['des'],'str',true,'',	 5,255);							
		$this->checkFormInput('Chủ đề Spam','subject',$this->spam_content['subject'],'str',true,'',5,255);							
		$this->checkFormInput('Nội dung Spam','content',$this->spam_content['content'],'str',true,'',20);							

		if(!$this->errNum){	
			$id=DB::insert('spam_content',$this->spam_content);
			if($id){
				if($this->spam_content['status']){
					DB::query("UPDATE spam_content SET status=0 WHERE id!=$id");
				}
				Url::redirect_current();
			}
			else{
				$this->setFormError('','Không cập nhật được CSDL!');
			}
		}
	}
	
	function draw(){	
		global $display;
		$this->beginForm();
		$display->add('msg',$this->showFormErrorMessages(1));
		
		$display->add('des',		stripslashes($this->spam_content['des']));
		$display->add('subject',	stripslashes($this->spam_content['subject']));
		$display->add('content',	stripslashes($this->spam_content['content']));
		$display->add('status',		$this->spam_content['status']);
		
		$display->output('AddContent');
		$this->endForm();
	}
}
?>